home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: checkTransState.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:30 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "serverinfo.h"
- #include "sm_state.h"
- #include "volume.h"
- #include "io_extfuncs.h"
- #include "trans_funcs.h"
- #include "msg_funcs.h"
- #include "sm_globals.h"
- #include "trans_globals.h"
-
-
- TID*
- getLocalTid()
- {
- return &(TransRec.clientTid);
- }
-
- int
- checkLocalTransState ()
- {
- TRANSREC *transRec;
-
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("client state %d",
- TransRec.clientTransState));
-
- transRec = findTransRec(getLocalTid());
-
- transRec->abortIfError = FALSE;
- /* we reset this regardless of the state because
- * we don't want the FAIL macro in the caller
- * to try to abort the tx if, say, we
- * were in an illegitimate state
- */
-
- switch (transRec->clientTransState) {
- case T_ACTIVE:
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("checkLocalTransState-OK"));
- return esmNOERROR;
-
- case T_ABORT:
- SM_ERROR(TYPE_USER, esmTRANSABORTED);
- break;
-
- case T_INACTIVE:
- SM_ERROR(TYPE_USER, esmNOACTIVETRANS);
- break;
-
- case T_PREPARED:
- SM_ERROR(TYPE_USER, esmTRANSPREPARED);
- break;
-
- default:
- /* internal error: the only states that a tx can
- * have on the client side are T_ACTIVE, T_INACTIVE, T_PREPARED, and T_ABORT
- */
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- break;
- }
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("checkLocalTransState-FAILURE"));
- return esmFAILURE;
- }
-
- TID *
- getServerTid (
- SERVERINFO *serverInfo,
- VOLID volid,
- TRANSREC *transRec
- )
- {
- SERVERTRANSREC *st;
-
- if(serverInfo == NULL) {
- VOLREC *volRec;
-
- SM_ASSERT(LEVEL_1, (volid != NULLVOLID));
-
- volRec = io_FindVolId(volid);
-
- SM_ASSERT(LEVEL_1, (volRec != NULL));
- SM_ASSERT(LEVEL_1, (volRec->serverInfo != NULL));
- serverInfo = volRec->serverInfo;
-
- }
-
- TRPRINT(TR_TRANS, TR_LEVEL_1,
- ("searching for server in participants"));
- for (st = (SERVERTRANSREC *)
- FIRST_LIST_ELEMENT(&(transRec->participants));
- (st != NULL) && (st->serverInfo != serverInfo);
- st = (SERVERTRANSREC *)NEXT_LIST_ELEMENT(&(st->participants))
- ) ;
-
- if(st == NULL) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
- if( (st->serverTransState != T_ACTIVE) &&
- (st->serverTransState != T_PREPARED)) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- return &(st->tid);
- }
-
- int
- checkTransState (
- VOLID volid
- )
- {
- SERVERTRANSREC *st;
- VOLREC *volRec;
-
-
- if( checkLocalTransState() != esmNOERROR) {
- return esmFAILURE;
- }
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("checkTransState volid %d", volid));
-
- /*
- * see if we know about this volume
- */
- volRec = io_FindVolId(volid);
- if(volRec == NULL) {
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("volume for volid %d NOT found",volid));
- return esmFAILURE;
- }
-
- if((SM_State.serverInfo = volRec->serverInfo) == NULL) {
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("server for volid %d NOT found",volid));
- return esmFAILURE;
- }
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("server for volid %d found",volid));
-
- SM_State.logInfo = &(SM_State.serverInfo->logInfo);
- SM_State.logLevel =
- (volRec->properties & VOL_TEMP)? LOG_NONE: SM_State.defaultLogLevel;
-
- TRPRINT(TR_TRANS, TR_LEVEL_1,
- ("searching for server in participants"));
- for (st = (SERVERTRANSREC *)
- FIRST_LIST_ELEMENT(&(TransRec.participants));
- (st != NULL) && (st->serverInfo != volRec->serverInfo);
- st = (SERVERTRANSREC *)NEXT_LIST_ELEMENT(&(st->participants))
- ) ;
-
- if(st == NULL) {
- /* should have been added by verifyServer() */
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
- /*
- * what is the remote server's tx state?
- */
- switch( st->serverTransState ) {
- case T_ACTIVE:
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("checkTransState(volid %d)-OK", volid));
- SM_State.serverTid = st->tid; /* temp kludge */
- break;
-
- case T_ABORT:
- SM_ERROR(TYPE_USER, esmTRANSABORTED);
- return esmFAILURE;
-
- case T_INACTIVE:
- /* really, we should not get here */
- SM_ERROR(TYPE_USER, esmNOACTIVETRANS);
- break;
-
- case T_PREPARED:
- SM_ERROR(TYPE_USER, esmTRANSPREPARED);
- break;
-
- default:
- SM_ERROR(TYPE_USER, esmINTERNAL);
- return esmFAILURE;
- }
- return esmNOERROR;
- }
-
- int
- checkVolumeState (
- VOLID volid
- )
- {
- VOLREC *volRec;
-
- volRec = io_FindVolId(volid);
- if(volRec == NULL) {
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("volume for volid %d NOT found",volid));
- return esmFAILURE;
- }
-
- if((SM_State.serverInfo = volRec->serverInfo) == NULL) {
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("server for volid %d NOT found",volid));
- return esmFAILURE;
- }
- TRPRINT(TR_TRANS, TR_LEVEL_1, ("server for volid %d found",volid));
-
- SM_State.logInfo = &(SM_State.serverInfo->logInfo);
- SM_State.logLevel = SM_State.defaultLogLevel;
-
- return esmNOERROR;
- }
-
-